import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';

class GooditemCard extends StatefulWidget {
  GooditemCard({Key key, this.commodityId, this.num}) : super(key: key);

  String commodityId;
  String num;

  @override
  _GooditemCardState createState() => _GooditemCardState();
}

class _GooditemCardState extends State<GooditemCard> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getinfo();
  }

  var info;

  _getinfo() async {
    var response = await Http.get(
        '/commodity/getById?id=' + widget.commodityId);
    info = response;
    if(mounted)setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      // color: Colors.red,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            decoration: new BoxDecoration(
              color: Color.fromRGBO(0, 0, 0, 0.04),
              borderRadius: new BorderRadius.circular((8.0)),
            ),
            child: info != null ?Image.network(
              info == null ? '加载中' : info["imgurl1"],
              width: 80,
              height: 80,
            ):null,
          ),
          SizedBox(width:12),
          Expanded(
            flex: 3,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 12,),
                Container(
                  child: Text(
                    info == null ? '加载中' : info["name"],
                    softWrap: true,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 14, color: Color(0xFF313131)),
                  ),
                ),
                Container(
                  // width: 188,
                  child: Text(
                    info == null ? '加载中' : info["intro"],
                    maxLines: 2,
                    softWrap: true,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontSize: 12, color: Colors.black54),
                  ),
                ),
                
              ],
            ),
          ),
          Expanded(
            flex: 1,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                SizedBox(height: 12,),
                Text(
                    info == null ?'加载中' : '￥${info["money"]}',
                    style: TextStyle(fontSize: 14, color: Colors.black87),
                  ),
                  Container(
                      margin: EdgeInsets.only(right: 4),
                      padding: EdgeInsets.only(top: 4),
                      child: Text(
                        'x' + widget.num.toString(),
                        style: TextStyle(
                            fontSize: 11, color: Colors.blueGrey[700]),
                      ),
                    )
              ],
            ),
          )
        ],
      ),
    );
  }
}
